package com.aso114.project.exam;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.adapter.ExpositionCardAdapter;
import com.aso114.project.base.BaseSimpleActivity;
import com.aso114.project.bean.QuestionBaseBean;
import com.aso114.project.util.SystemBarHelper;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by asus on 2019/1/16.
 */

public class ExpositionCardActivity extends BaseSimpleActivity {
    @BindView(R.id.layout_title_bar_back_iv)
    ImageView layoutTitleBarBackIv;
    @BindView(R.id.layout_title_bar_title_tv)
    TextView layoutTitleBarTitleTv;
    @BindView(R.id.layout_title_bar_right_iv)
    ImageView layoutTitleBarRightIv;
    @BindView(R.id.layout_title_bar_right_tv)
    TextView layoutTitleBarRightTv;
    @BindView(R.id.exposition_card_titel)
    TextView expositionCardTitel;
    @BindView(R.id.exposition_card_grid)
    GridView expositionCardGrid;

    ArrayList<QuestionBaseBean> baseBean = new ArrayList<>();
    @BindView(R.id.title_top_ly)
    RelativeLayout titleTopLy;
    private ExpositionCardAdapter cardAdapter;

    @Override
    protected int getResouseId() {
        return R.layout.activity_exposition_card;
    }

    @Override
    protected void initView() {
        SystemBarHelper.immersiveStatusBar(this);
        SystemBarHelper.setHeightAndPadding(this, titleTopLy);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            SystemBarHelper.immersiveStatusBar(this, 0);
            SystemBarHelper.setStatusBarDarkMode(this);
        }
        layoutTitleBarTitleTv.setText("答题卡");
        cardAdapter = new ExpositionCardAdapter(this, baseBean);
        expositionCardGrid.setAdapter(cardAdapter);
        expositionCardGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                intent.putExtra("position", position);
                setResult(2, intent);
                finish();
            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEventMainThread(ArrayList<QuestionBaseBean> bean) {
        this.baseBean = bean;
        expositionCardTitel.setText(baseBean.get(0).getRealPaperTitle());
        cardAdapter.setData(baseBean);
        cardAdapter.notifyDataSetChanged();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void getBroadcast(Context context, Intent intent) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @OnClick(R.id.layout_title_bar_back_iv)
    public void onViewClicked() {
        finish();
    }
}
